package com.woniuxy.educationplatform.controller;

import com.woniuxy.educationplatform.bean.LiveBean;
import com.woniuxy.educationplatform.service.ILiveService;
import com.woniuxy.educationplatform.service.ITeacherService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/live")

public class LiveController {

    @Resource
    private ILiveService liveServiceImpl;
    @Resource
    private ITeacherService teacherServiceImpl;

    @RequestMapping("/findAll")
    public List<LiveBean> findAll(){
        System.out.println("查询所有");
        return liveServiceImpl.findAll();
    }

    @RequestMapping("/more")
    public void saveLiveBean(String teacherName,String liveName,Long ltype, @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date createTime){
        System.out.println("开始新建");
        System.out.println(liveName);
        System.out.println(ltype);
        System.out.println(createTime);
        System.out.println(teacherName);
        LiveBean liveBean=new LiveBean();
        liveBean.setLiveName(liveName);
        liveBean.setCreateTime(createTime);
        liveBean.setLtype(ltype);
        liveBean.setTeacherName(teacherName);
        liveServiceImpl.saveLiveBean(liveBean);
        System.out.println("新建完成");

    }

    @RequestMapping("/getTeacher")
    public String[] getTeacher(){
        System.out.println("获取所有老师姓名中");
       return teacherServiceImpl.getTeacher();
    }

    @RequestMapping("/find")
    public List<LiveBean> find(String liveName,Long status,Long type){
        System.out.println("开始根据条件查询直播表");
        System.out.println(liveName);
        System.out.println(status);
        System.out.println(type);
        LiveBean liveBean=new LiveBean();
        liveBean.setLiveName(liveName);
        liveBean.setStatus(status);
        liveBean.setLtype(type);
        return liveServiceImpl.findOneByCondition(liveBean);
    }

    @RequestMapping("/change")
    public void changeStatus(Long status,Long id){
        System.out.println(status);
        System.out.println(id);
        status+=1;
        System.out.println(status);
        liveServiceImpl.changeStatus(status,id);
        System.out.println("状态修改完成");

    }

    @RequestMapping("/del")
    public void del(Long id){
        System.out.println("开始删除");
        System.out.println(id);
        liveServiceImpl.delete(id);
        System.out.println("删除完毕");
    }
}

